package hwOne2;

import edu.princeton.cs.algs4.Point2D;
import edu.princeton.cs.algs4.StdDraw;
import edu.princeton.cs.algs4.StdOut;

/**
 * 1.2.10
 */
public class VisualCounter {
    private int oper;
    private int absMax;
    private int count = 0;
    public VisualCounter(int N, int max) {
        oper = N;
        absMax = max;
        StdDraw.setCanvasSize(800, 800);
        StdDraw.setXscale(0, 1);
        StdDraw.setYscale(0, 1);
        StdDraw.setPenRadius(0.01);
    }

    public void increment() {
        if (count == oper) {
            StdOut.println("已达到最大操作次数");
            return;
        }
        if (count == absMax) {
            StdOut.println("已达到最大绝对值");
            return;
        }
        count++;
        drawPoint();
    }

    void drawPoint() {

        Point2D p = new Point2D(0.1 * count, 0.1 * count);
        p.draw();
    }

    public int tally() {
        return count;
    }

    public static void main(String[] args) {
        int N = 100;
        int max = 3;
        VisualCounter visCou = new VisualCounter(N, max);
        for (int i = 0; i < N; i++) {
            visCou.increment();
        }
    }
}
